package modeller.databasedesignmodel.transaction;

import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedList;

/**
 * Created by IntelliJ IDEA.
 * User: Jason Ye
 * Date: 21/01/2012
 * Time: 16:24
 */
public class Transaction implements Serializable {

    private double m_transactionPrevalence;
    private String m_transactionName;
    private boolean m_isOpen;

    private LinkedList<IProceduralStatement> m_proceduralStatements;

    public Transaction(int id) {
        this(id, 0);
    }

    public Transaction(boolean isOpen, String name, double prevalence) {
        m_isOpen = isOpen;
        m_transactionPrevalence = prevalence;
        m_proceduralStatements = new LinkedList<IProceduralStatement>();
        m_transactionName = name;
    }

    public Transaction(int id, int prevalence) {
        this(false, Integer.toString(id), prevalence);
    }

    public double getTransactionPrevalence() {
        return m_transactionPrevalence;
    }


    public void setTransactionPrevalence(int m_transactionPrevalence) {
        this.m_transactionPrevalence = m_transactionPrevalence;
    }

    public LinkedList<IProceduralStatement> getProceduralStatements() {
        return m_proceduralStatements;
    }

    public void setProceduralStatements(LinkedList<IProceduralStatement> m_proceduralStatements) {
        this.m_proceduralStatements = m_proceduralStatements;
    }

    public void addProcStmt(IProceduralStatement stmt) {
        m_proceduralStatements.add(stmt);
    }

    public void removeProcStmt(IProceduralStatement stmt) {
        m_proceduralStatements.remove(stmt);
    }

    @Override
    public String toString() {

        StringBuffer buffer = new StringBuffer();

        buffer.append("Transaction name: " + m_transactionName + " has prevalence " + m_transactionPrevalence + ":\n");
        buffer.append("\n\tProcedural Statements:\n");

        for (IProceduralStatement statement : m_proceduralStatements) {
            // buffer.append(statement.myToString() + "\n");
        }
        return buffer.toString();
    }

    public String getTransactionName() {
        return m_transactionName;
    }

    public boolean isOpen() {
        return m_isOpen;
    }
}
